﻿import { Vector3 } from "./Vector3";
import { TriIndex } from "./IndexTriangle";

export class DataProvider {
    public static getPoints(index: number): Array<Vector3> {
        if (index == 0) return this.getMyPoints(DataProvider.points0);
        if (index == 1) return this.getMyPoints(DataProvider.points1);
        return null;
    }

    public static getIndex(index: number): Array<TriIndex> {
        if (index == 0) return this.getMyIndex(DataProvider.triangle0);
        if (index == 1) return this.getMyIndex(DataProvider.triangle1);
        return null;
    }

    private static getMyPoints(text: string): Array<Vector3> {
        var arr = new Array<Vector3>();
        var list = text.split(' ');
        var len = list.length;
        var v = 0;
        var vec, x, y, z;
        for (var i = 0; i < len; i++) {
            var s = list[i].trim();
            if (s.length > 0) {
                var n = Number(s);
                if (v == 2) {
                    z = n;
                    vec = new Vector3(x, y, z);
                    arr.push(vec);
                    v = -1;
                } else if (v == 1) {
                    y = n;
                } else {
                    x = n;
                }
                v++;
            }
        }
        return arr;
    }

    private static getMyIndex(text: string): Array<TriIndex> {
        var arr = new Array<TriIndex>();
        var list = text.split(' ');
        var len = list.length;
        var v = 0, a = 0, b = 0, c = 0;
        for (var i = 0; i < len; i++) {
            var s = list[i].trim();
            if (s.length > 0) {
                var n = Number(s);
                if (v == 1) {
                    a = n;
                } else if (v == 2) {
                    b = n;
                } else if (v == 3) {
                    c = n;
                    var index = new TriIndex(a, b, c);
                    arr.push(index);
                    v = -1;
                }
                v++;
            }
        }
        return arr;
    }

    private static points0 =
        "-70.936200 68.746129 5.699911  \
         -79.409079 46.193584 -37.99344 \
         -46.737531 85.862375 -0.020634 \
         -24.817911 65.304989 70.755897 \
         -83.829696 18.891855 41.305464 \
         -25.627082 87.897464 -37.69517 \
         -42.697380 38.175984 -77.32751 \
         28.334069 85.356626 22.064270  \
         23.178230 80.608480 -19.333350 \
         83.499367 51.231609 -15.454207 \
         54.624906 18.954945 -77.762162 \
         -14.507812 43.531160 -85.35280 \
         11.117186 24.698034 -94.227293 \
         -14.554359 31.411031 -89.58684 \
         -45.447373 7.236165 -82.878786 \
         -15.619894 1.559147 -95.030843 \
         -7.878712 -20.514929 -96.75622 \
         -25.164370 -11.191513 -94.3372 \
         -20.301721 -24.239809 -93.4257 \
         -59.239544 -24.695010 -74.7116 \
         22.454309 -50.704252 -79.43784 \
         -7.311852 -72.371603 -51.86890 \
         21.643908 -15.794418 -95.94873 \
         36.453498 -40.526668 -82.23603 \
         22.811693 -83.145253 -2.313925 \
         71.248826 20.540836 -41.996301 \
         91.169708 38.628647 0.813394   \
         65.600492 -59.602221 29.478920 \
         18.282294 -69.174587 65.589913 \
         28.413570 -50.236195 77.645886 \
         -11.762729 -92.522254 12.71202 \
         14.791199 -69.707378 63.186384 \
         -23.519156 -88.939673 -3.27811 \
         -72.763967 -44.285682 32.34160 \
         -40.031767 -52.853816 -55.2259 \
         -86.392224 -32.715324 -8.62672 \
         -79.922191 -2.021626 -57.76178 \
         -55.257378 -9.904947 65.116492 \
         -28.053051 4.627308 94.514925  \
         -7.124669 -8.860165 99.071859  \
         6.329831 9.329788 99.281821    \
         8.533446 -21.014414 96.363954  \
         -1.198076 -8.819546 99.508076  \
         36.162074 -5.833734 92.080555  \
         43.946261 -2.069684 87.715140  \
         2.376648 47.126764 88.159087   \
         56.565229 -5.730861 81.104660  \
         24.758978 55.372798 70.680337  \
         52.528945 36.100463 58.023701  \
         -10.815552 39.187430 88.917789 \
         82.479266 50.281834 9.371098   \
         86.007465 46.669003 2.122000   \
         76.821412 19.597501 41.066077  \
         -21.221450 28.697173 91.333643 \
         -31.747454 15.558376 90.676131 \
         18.480008 -18.852265 94.094241 ";

    private static triangle0 =
        "3 0 1 2       \
         3 0 2 3       \
         3 4 1 0       \
         3 1 5 2       \
         3 6 5 1       \
         3 5 7 2       \
         3 2 7 3       \
         3 5 8 7       \
         3 8 9 7       \
         3 8 5 10      \
         3 8 10 9      \
         3 5 11 10     \
         3 11 12 10    \
         3 6 11 5      \
         3 6 13 11     \
         3 13 6 14     \
         3 11 13 12    \
         3 13 15 12    \
         3 15 16 12    \
         3 17 15 13    \
         3 17 13 14    \
         3 15 17 16    \
         3 17 18 16    \
         3 19 18 17    \
         3 18 20 16    \
         3 18 21 20    \
         3 16 20 22    \
         3 12 16 22    \
         3 20 23 22    \
         3 23 20 24    \
         3 22 23 10    \
         3 22 10 12    \
         3 23 25 10    \
         3 10 25 26    \
         3 25 23 27    \
         3 26 25 27    \
         3 23 24 27    \
         3 27 24 28    \
         3 29 27 28    \
         3 24 30 28    \
         3 28 30 31    \
         3 24 21 30    \
         3 30 21 32    \
         3 20 21 24    \
         3 33 30 32    \
         3 32 21 34    \
         3 34 35 32    \
         3 34 21 19    \
         3 34 19 35    \
         3 19 21 18    \
         3 35 19 36    \
         3 35 36 1     \
         3 36 19 14    \
         3 14 6 36     \
         3 14 19 17    \
         3 36 6 1      \
         3 35 1 4      \
         3 33 35 4     \
         3 37 33 4     \
         3 33 32 35    \
         3 37 4 38     \
         3 38 33 37    \
         3 39 33 38    \
         3 40 39 38    \
         3 31 33 39    \
         3 39 28 31    \
         3 31 30 33    \
         3 39 41 28    \
         3 41 29 28    \
         3 41 39 42    \
         3 41 42 43    \
         3 42 39 40    \
         3 43 42 40    \
         3 44 43 40    \
         3 44 40 45    \
         3 43 44 46    \
         3 43 46 29    \
         3 46 44 47    \
         3 48 46 47    \
         3 47 44 45    \
         3 3 47 45     \
         3 49 3 45     \
         3 7 47 3      \
         3 7 50 47     \
         3 47 50 48    \
         3 7 9 50      \
         3 50 9 51     \
         3 50 51 26    \
         3 51 9 26     \
         3 10 26 9     \
         3 50 26 52    \
         3 50 52 48    \
         3 26 27 52    \
         3 52 27 46    \
         3 52 46 48    \
         3 46 27 29    \
         3 53 49 45    \
         3 49 53 3     \
         3 53 54 3     \
         3 38 54 53    \
         3 54 4 3      \
         3 38 4 54     \
         3 4 0 3       \
         3 40 38 53    \
         3 40 53 45    \
         3 55 43 29    \
         3 41 55 29    \
         3 41 43 55    ";

    private static points1 =
        "    46.452321 51.201509 -82.298096" +
        "14.748323 11.467748 -91.626213    " +
        "55.486975 20.066090 -96.599735    " +
        "75.367076 28.201039 -91.097691    " +
        "-0.027299 72.816027 -42.779273    " +
        "42.554824 -0.815063 -97.071361    " +
        "23.904771 -32.866433 -89.142160   " +
        "77.740154 17.887851 -91.287736    " +
        "65.738838 -22.305259 -88.091212   " +
        "125.231380 -25.468020 -57.759419  " +
        "41.729108 -71.151708 -55.851124   " +
        "117.231105 22.827705 -64.018318   " +
        "122.377802 54.091436 -42.790181   " +
        "144.326260 -13.430646 21.697028   " +
        "89.145069 88.015383 -19.123748    " +
        "94.889756 82.802930 10.191436     " +
        "51.361661 72.951440 -50.428984    " +
        "77.059866 91.633451 1.520687      " +
        "16.778907 80.788612 45.881961     " +
        "100.954794 65.797306 48.283010    " +
        "-6.100661 58.919573 54.459662     " +
        "33.061536 7.088219 93.559275      " +
        "-44.913644 17.544312 4.664182     " +
        "-28.759308 30.997136 47.391344    " +
        "-14.964085 -12.300034 -64.486859  " +
        "-46.165674 -19.909622 -2.653394   " +
        "12.426538 -52.430087 -75.291428   " +
        "-5.564146 -36.080805 -63.272042   " +
        "40.531958 -84.975847 -36.890585   " +
        "33.898091 -92.666032 -21.239369   " +
        "100.792064 -59.404283 41.512466   " +
        "48.047872 -85.567535 5.153077     " +
        "92.339714 -41.549479 65.741341    " +
        "124.581417 5.165894 58.084855     " +
        "79.252971 -48.829490 75.717420    " +
        "72.826645 -66.632428 64.610533    " +
        "80.550377 -40.069106 80.245269    " +
        "61.550048 -34.570421 91.422142    " +
        "89.976457 3.200144 90.636804      " +
        "41.292790 -43.902957 88.500500    " +
        "55.570374 -18.159710 97.350561    " +
        "-36.986777 -44.298934 -2.943437   " +
        "-14.749608 7.688329 53.501307     " +
        "26.427489 -0.699532 92.088491     " +
        "43.346643 -14.388964 98.030253    " +
        "63.752982 10.532432 93.632820     " +
        "57.501487 22.351408 89.009260     " +
        "102.906158 53.122548 61.123983    " +
        "123.132947 21.725728 49.905560    ";

    private static triangle1 =
        "3 0 1 2    " +
        "3 0 2 3    " +
        "3 4 1 0    " +
        "3 1 5 2    " +
        "3 1 6 5    " +
        "3 2 5 7    " +
        "3 3 2 7    " +
        "3 8 7 5    " +
        "3 5 6 8    " +
        "3 8 9 7    " +
        "3 8 10 9   " +
        "3 7 9 11   " +
        "3 7 11 3   " +
        "3 9 12 11  " +
        "3 9 13 12  " +
        "3 3 11 12  " +
        "3 0 3 12   " +
        "3 14 0 12  " +
        "3 15 14 12 " +
        "3 16 0 14  " +
        "3 4 16 14  " +
        "3 16 4 0   " +
        "3 17 4 14  " +
        "3 15 17 14 " +
        "3 17 18 4  " +
        "3 19 18 17 " +
        "3 20 4 18  " +
        "3 21 20 18 " +
        "3 20 22 4  " +
        "3 20 23 22 " +
        "3 22 24 4  " +
        "3 22 25 24 " +
        "3 4 24 1   " +
        "3 1 24 6   " +
        "3 24 26 6  " +
        "3 27 26 24 " +
        "3 26 10 6  " +
        "3 26 28 10 " +
        "3 6 10 8   " +
        "3 29 28 26 " +
        "3 10 28 9  " +
        "3 9 28 29  " +
        "3 30 9 29  " +
        "3 31 30 29 " +
        "3 9 30 13  " +
        "3 13 30 32 " +
        "3 33 13 32 " +
        "3 34 32 30 " +
        "3 34 30 35 " +
        "3 32 34 36 " +
        "3 32 36 33 " +
        "3 36 34 37 " +
        "3 38 36 37 " +
        "3 37 34 35 " +
        "3 37 35 39 " +
        "3 40 37 39 " +
        "3 35 31 39 " +
        "3 31 29 39 " +
        "3 35 30 31 " +
        "3 29 41 39 " +
        "3 39 41 42 " +
        "3 41 29 26 " +
        "3 41 26 27 " +
        "3 41 27 24 " +
        "3 25 41 24 " +
        "3 41 25 23 " +
        "3 42 41 23 " +
        "3 25 22 23 " +
        "3 23 43 42 " +
        "3 42 43 39 " +
        "3 20 43 23 " +
        "3 21 43 20 " +
        "3 21 44 43 " +
        "3 43 44 39 " +
        "3 45 44 21 " +
        "3 46 45 21 " +
        "3 45 40 44 " +
        "3 44 40 39 " +
        "3 38 40 45 " +
        "3 47 38 45 " +
        "3 38 37 40 " +
        "3 47 45 46 " +
        "3 33 38 47 " +
        "3 47 48 33 " +
        "3 33 36 38 " +
        "3 47 19 48 " +
        "3 48 13 33 " +
        "3 48 12 13 " +
        "3 19 12 48 " +
        "3 19 15 12 " +
        "3 19 17 15 " +
        "3 47 18 19 " +
        "3 47 46 18 " +
        "3 21 18 46";
}